<!-- 我的界面  -->
<template>
	<view class="my-page">
		<!-- 头像昵称部分 登录 -->
		<view class="my-name" v-if="exist">
			<image :src="user_info.avatarUrl" mode="aspectFit"></image>
			<text>{{user_info.nickName}}</text>
		</view>
		<!-- 头像昵称部分 未登录 -->
		<view class="my-name" v-else="!exist" @click="goLogin">
			<image src="/static/images/unlogin.svg" mode="aspectFit"></image>
			<text>点击登录</text>
		</view>

		<!-- 水波纹图片 -->
		<image class="wave-img" src="https://qita-1252107261.cos.ap-chengdu.myqcloud.com/boliang" mode="scaleToFill"></image>
	</view>

	<view class="my-order">
		<view class="my-order-title more">
			<view>我的订单</view>
			<view class="more" v-for="(item,index) in data.whole" :key="index" @click="viewOrder(item.id,item.query)">
				<text>{{item.name}}</text>
				<image :src="item.icon" mode="aspectFit"></image>
			</view>
		</view>
		<view class="order-state">
			<view v-for="(item,index) in data.list" :key="index" @click="viewOrder(item.id,item.query)">
				<image :src="item.icon" mode="aspectFit"></image>
				<text>{{item.name}}</text>
			</view>
		</view>
	</view>

	<view class="my-other">
		<view @click="myCollect">
			<image src="/static/images/mine-collect.svg" mode="aspectFit"></image>
			<text>我的收藏</text>
			<image src="/static/images/right-arrow.svg" mode="aspectFit" class="my-other-deta"></image>
		</view>
		<view @click="viewAddress">
			<image src="/static/images/receive-locating.svg" mode="aspectFit"></image>
			<text>收货地址</text>
			<image src="/static/images/right-arrow.svg" mode="aspectFit" class="my-other-deta"></image>
		</view>
		<view @click="callStore">
			<image src="/static/images/feedback.svg" mode="aspectFit"></image>
			<text>联系门店</text>
			<image src="/static/images/right-arrow.svg" mode="aspectFit" class="my-other-deta"></image>
		</view>
	</view>

	<!-- 登陆弹窗 -->
	<Login></Login>

</template>

<script setup>
	import { reactive, toRefs, watch } from 'vue'
	import { onShow } from '@dcloudio/uni-app'
	import Login from '@/components/login-view.vue'
	import { login_box } from '@/public/package-js/passValue.js'

	const data = reactive({
		whole: [
			{
				id: 0,
				name: '查看全部订单',
				icon: '/static/images/right-arrow.svg',
				query: {}
			}
		],
		list: [
			{
				id: 1,
				name: '待支付',
				icon: '/static/images/wait-pay.svg',
				query: { pay_status: 0 }
			},
			{
				id: 2,
				name: '待发货',
				icon: '/static/images/wait-delivery.svg',
				query: { pay_status: 1, deliver_status: 0 }
			},
			{
				id: 3,
				name: '待收货',
				icon: '/static/images/wait-receive.svg',
				query: { pay_status: 1, deliver_status: 1 }
			},
			{
				id: 4,
				name: '待评价',
				icon: '/static/images/wait-comment.svg',
				query: { pay_status: 1, deliver_status: 2, evaluate: false }
			}
		]
	})


	// 定义用户数据
	const user = reactive({
		user_info: {}, // 用户信息
		exist: false // 记录是否登陆，用于是否调起登录弹窗
	})
	const { user_info, exist } = toRefs(user)

	// 1、查询是否登陆
	onShow(() => {
		loginStatus()
	})

	function loginStatus() {
		const user_data = uni.getStorageSync('user_info') //取出本地缓存的用户信息
		if (user_data) {
			user.exist = true
			user.user_info = user_data
		} else {
			user.exist = false
		}
	}

	// 2、调用登陆弹窗
	function goLogin() {
		login_box.show = true
	}

	// 监听登陆是否成功，成功则重新取收藏和购物车的数据
	watch(() => login_box.response, (newVal, oldVal) => {
		loginStatus()
	})

	// 3、查看各种订单
	function viewOrder(index, query) {
		if (user.exist) {
			let obj = JSON.stringify({ index, query })
			uni.navigateTo({
				url: `/pages/order/order?obj=${obj}`
			})
		} else {
			login_box.show = true
		}
	}

	// 4、查看收货地址
	function viewAddress() {
		if (user.exist) {
			uni.navigateTo({
				url: '/pages/receiver-address/receiver-address'
			})
		} else {
			login_box.show = true
		}
	}

	// 5、我的收藏
	function myCollect() {
		if (user.exist) {
			uni.navigateTo({
				url: '/pages/collection/collection'
			})
		} else {
			login_box.show = true
		}
	}

	// 6、联系门店
	function callStore() {
		uni.makePhoneCall({
			phoneNumber: '19149839617'
		})
	}
</script>

<style scoped>
	.my-page {
		height: 300rpx;
		/* 渐变背景色 */
		background: linear-gradient(to bottom, #e94b37 25%, #e59f95 100%);
		position: relative;
		padding-top: 100rpx;
	}

	.my-name image {
		display: block;
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin-bottom: 10rpx;
	}

	.my-name {
		color: #FFFFFF;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 230rpx;
		font-size: 33rpx;
		z-index: 9;
		position: absolute;
		left: 0;
		right: 0;
	}

	.wave-img {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 170rpx;
		/* mix-blend-mode 属性描述了元素的内容应该与元素的直系父元素的内容和元素的背景如何混合。 */
		mix-blend-mode: screen;
		/* 滤色*/
	}

	/* 我的订单 */
	.my-order {
		margin-top: 20rpx;
		padding: 0 20rpx;
	}

	.my-order-title image {
		width: 30rpx;
		height: 30rpx;
		display: block;
		margin-left: 10rpx;
	}

	.my-order-title {
		display: flex;
		justify-content: space-between;
	}

	.my-order-title view:nth-child(1) {
		font-weight: bold;
	}

	.my-order-title view:nth-child(2) {
		font-size: 25rpx;
		color: #cfcfcf;
	}

	.more {
		display: flex;
		align-items: center;
	}

	.order-state image {
		display: block;
		width: 50rpx;
		height: 50rpx;
		margin-bottom: 10rpx;
	}

	.order-state {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 30rpx;
	}

	.order-state view {
		display: flex;
		align-items: center;
		flex-direction: column;
		color: #4f4f4f;
	}

	/* 其他功能 */
	.my-other {
		background-color: #FFFFFF;
		margin: 50rpx 20rpx 20rpx 20rpx;
		box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
		border-radius: 6rpx;
		padding: 0 10rpx;
		color: #828282;
	}

	.my-other image {
		display: block;
		width: 35rpx;
		height: 35rpx;
		margin-right: 20rpx;
	}

	.my-other view {
		display: flex;
		align-items: center;
		padding: 30rpx 0;
	}

	.my-other view:nth-child(2) {
		border-bottom: 1rpx solid #e0e0e0;
		border-top: 1rpx solid #e0e0e0;
	}

	.my-other text {
		flex: 1;
	}

	.my-other-deta {
		width: 30rpx !important;
		height: 30rpx !important;
		margin: 0 !important;
	}
</style>
